home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
PROBLEMS
/
BENCHMARK
/
BUBBLESORT
/
bubbletest
/
perl
/
source
< prev
next >
Wrap
Text File
|
1992-05-15
|
740b
|
36 lines
#!/l/bin/perl
$\ = "\n"; # set output record separator
# pseudo ramdom
$pseudoramdom = 123456;
for ($count = 0; $count < 1000; $count = $count + 1) {
$pseudoramdom = ($pseudoramdom + 234567) % 567 + 345;
$a[$count] = $pseudoramdom;
print (($a[$count]));
}
system('time');
&bubblesort(*a, 1000);
system('time');
for ($count = 0; $count < 1000; $count = $count + 1) {
print (($a[$count]));
}
sub bubblesort {
local(*a, $len, $flag, $count, $temp) = @_;
$flag = 1;
while ($flag) {
$flag = 0;
for ($count = 0; $count < $len - 1; $count = $count + 1) {
if ($a[$count] gt $a[$count + 1]) { #???
$temp = $a[$count];
$a[$count] = $a[$count + 1];
$a[$count + 1] = $temp;
$flag = 1;
}
}
}
}